package com.yidu.logisticssystem.controller;

import com.yidu.logisticssystem.entity.LogisticsWaytype;
import com.yidu.logisticssystem.service.LogisticsWaytypeService;
import com.yidu.logisticssystem.utils.BaseMessage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 货物类型表(LogisticsWaytype)表控制层
 *
 * @author makejava
 * @since 2021-03-08 16:46:58
 */
@Api(tags = "货物类型接口")
@RestController
@RequestMapping("logisticsWaytype")
public class LogisticsWaytypeController {
    /**
     * 服务对象
     */
    @Resource
    private LogisticsWaytypeService logisticsWaytypeService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public LogisticsWaytype selectOne(Integer id) {
        return this.logisticsWaytypeService.queryById(id);
    }

    /**
     * 查询所有
     * @return 所有数据
     */
    @ApiOperation(value = "查询所有货物类型",notes = "返回所有货物类型")
    @GetMapping("findAll")
    public BaseMessage findAll(){
        return BaseMessage.succes(logisticsWaytypeService.findAll());
    }

    /**
     * 增加货物类型
     * @param logisticsWaytype
     * @return 改变的行数
     */
    @ApiOperation(value = "增加或修改货物类型",notes = "返回改变的行数")
    @GetMapping("addOrUpdate")
    public BaseMessage insert(LogisticsWaytype logisticsWaytype){
        int rows=0;
        if(logisticsWaytype.getWaytypeId()==null){
            rows=logisticsWaytypeService.insert(logisticsWaytype);
        }else {
            rows=logisticsWaytypeService.update(logisticsWaytype);
        }

        return rows>0?BaseMessage.succes():BaseMessage.succes();
    }
}
